<?php
/* 
 * class.opinion.php
 * 我的城市首页-商家信息
 * @author samuel
 * @date 2009-05-23
 */
include_once 'class.mycityBase.php';
class mycity_opinion extends mycityBase {
    private $seller_id;
    private $step;


    function  __construct($core) {
        parent::__construct();
        //参数处理
	    $this->step = $this->params['step'] ? strtolower(trim($core->params['step'])) : 'index';
	    $this->seller_id = $this->params['sid'] ? (int)$this->params['sid'] : 0;
	    $this->user_id = $this->params['uid'] ? (int)$this->params['uid'] : 1;
	    $this->page = $this->params['page'] ? (int)$this->params['page'] : 1;
	    $this->type = $this->params['type'] ? trim($this->params['type']) : 'all';
	    if(!$this->user_id){
		    $this->error = "用户ID不合法！";
		    $this->jumpError();
		    exit;
	    }
	    if(!$this->seller_id){
		    $this->error = "商家ID不合法！";
		    $this->jumpError();
		    exit;
	    }

        $run = "run_" . $this->step;
        
        //header("Content-type: text/vnd.wap.wml");
        $this->$run();
    }

    
    function run_index(){
        $page_title = "我的城市-商家评价";
	    $content = "";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."' alt='返回上级'>返回上级</a><br/>";
	    //获取商家信息
	    $sellerBase = $this->core->load('seller::sellerBase');
	    $seller = $sellerBase->getSellerInfo($this->seller_id);
	    //获取评分人数
	    $grade_counts = $this->getSellerGrades($this->seller_id, '', true);
	    $content .= $seller['SellerNameCN'] . "(".$seller['SellerNo'].")<br/>";
	    $gradeIcons = $this->getSellerGradeIcon($seller['SellerGrade'], $grade_counts);
	    $content .= $gradeIcons."<br/>";
	    
	    $content .= "(已有".(int)$grade_counts."人评分)<br/>";
	    
	    //判断是否已经收藏过
	    $favor_tag = $this->core->load('myhome::myhomeBase')->getUserFavorites($this->user_id, $this->seller_id, true);
	    if(!$favor_tag){
	        $favor = "<a href='".$_SERVER['PHP_SELF']."?act=collect&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>收藏</a>|";
	    }
	    
	    //判断是否已经评分过
	    $grade_tag = $this->getSellerGrades($this->seller_id, $this->user_id, true);
	    if(!$grade_tag){
	        $grade = "<a href='".$_SERVER['PHP_SELF']."?act=grade&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>评分</a>|";
	    }
	
	    $content .= $favor.$grade."<a href='".$_SERVER['PHP_SELF']."?act=dfw&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>大富翁</a><br/>";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerinfo&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>信息</a>|<a href='".$_SERVER['PHP_SELF']."?act=sellerinfo&amp;step=discount&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>优惠</a>|<a href='".$_SERVER['PHP_SELF']."?act=special&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>特色</a><br/>";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=opinion&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>评价</a>|<a href='".$_SERVER['PHP_SELF']."?act=parking&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>停车</a>|<a href='".$_SERVER['PHP_SELF']."?act=realenv&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>实景</a><br/><br/>";
	
	    //商家评价
	    $content .= "-----------<br/>";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=opinion&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."'>全部</a>｜<a href='".$_SERVER['PHP_SELF']."?act=opinion&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."&amp;type=friends'>好友</a><br/>";
	    
	    $pagesize = 10;
	    $displaypage = 5;
	    $page = $this->page;
	    $current_url = $_SERVER['PHP_SELF']."?act=opinion&amp;uid=".$this->user_id."&amp;sid=".$this->seller_id."&amp;type=".$this->type;
	    
	    if($this->type == 'all'){
	        $sql = "SELECT count(*) FROM `fun_seller_opinion` WHERE 1 AND `SellerID`='".$this->seller_id."'";
            $counts = $this->core->db->get_var($sql);
            $totalPages = ceil($counts/$pagesize);
            $pager = $this->core->utility->wap_pager($totalPages, $page, $displaypage, $current_url);
            $arr_limit = array('offset'=>($page-1)*$pagesize, 'pagesize'=>$pagesize);
	        $opinions = $this->getSellerOpinion($this->seller_id,'',$arr_limit);
	        if($opinions){
	            foreach($opinions as $opinion){
	                $content .= $opinion['UserNickName'].":".$opinion['SellerUserOpinion']."(".$opinion['OpinionTime'].")<br/>";
	            }
	        }  
	    }else{
	        $friends = $this->getUserFriends($this->user_id);
	        if($friends){
	            foreach($friends as $friend){
	                $arr_fids[] = $friend['UserID'];
	            }
	            $str_fids = @implode(',', $arr_fids);
	            $sql = "SELECT count(*) FROM `fun_seller_opinion` WHERE 1 AND `SellerID`='".$this->seller_id."' AND `UserID` IN (".$str_fids.")";
                $counts = $this->core->db->get_var($sql);
                $totalPages = ceil($counts/$pagesize);
                $pager = $this->core->utility->wap_pager($totalPages, $page, $displaypage, $current_url);
	            $arr_limit = array('offset'=>($page-1)*$pagesize, 'pagesize'=>$pagesize);
	            $opinions = $this->getSellerOpinion($this->seller_id, $str_fids, $arr_limit);
	            if($opinions){
	                foreach($opinions as $opinion){
	                    $content .= $opinion['UserNickName'].":".$opinion['SellerUserOpinion']."(".$opinion['OpinionTime'].")<br/>";
	                }
	            }  
	        }
	    }
	    
	    
	    $content .= $pager."<br/><br/>";
	    
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."' alt='返回上级'>返回上级</a><br/>";
	    $content .= "<a href='' alt='建议帮助'>建议帮助</a>";



	    $this->core->tpl->assign('content', $content);
	    $this->core->tpl->assign('page_title', $page_title);
	    $this->core->tpl->display('comm.wml');
    }
}


?>
